package cn.wolfcode.luowowo.common.util;

import cn.wolfcode.luowowo.common.exception.DisplayableException;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AssertUtil {

    public static void hasLength(String value, String msg) {
        if (value == null || "".equals(value.trim())) {
            throw new DisplayableException(msg);
        }
    }

    public static void isEquals(String v1, String v2, String msg) {
        if (!v1.equals(v2)) {
            throw new DisplayableException(msg);
        }
    }

    /**
     * 验证手机号码符合性
     * @param str
     * @return
     */
    public static void isMobile(String str, String msg) {
        Pattern p = null;
        Matcher m = null;
        boolean isMatch = false;
        //制定验证条件
        String regex2 = "^((13[0-9])|(14[579])|(15([0-3,5-9]))|(16[6])|(17[0135678])|(18[0-9]|19[89]))\\d{8}$";

        p = Pattern.compile(regex2);
        m = p.matcher(str);
        if(!m.matches()){
            throw new DisplayableException(msg);
        }
    }
}
